package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;

class zbar {
   static byte[] a(int var0, String var1, FontSetting[] var2, WorksheetCollection var3) {
      com.aspose.cells.b.a.a.zd var5 = new com.aspose.cells.b.a.a.zd();

      int var4;
      int var8;
      for(int var6 = 0; var6 < var2.length; ++var6) {
         FontSetting var7 = var2[var6];
         if (var7.c() != null) {
            var3.a(var7.c());
            if (var7.getStartIndex() + var7.getLength() >= var1.length()) {
               var5.b(var7.getStartIndex(), var7.getFont().j());
               var4 = var5.e(var7.getStartIndex());

               while(var5.b() - 1 > var4) {
                  var5.d(var5.b() - 1);
               }
            } else {
               var5.b(var7.getStartIndex(), var7.getFont().j());
               var4 = var5.e(var7.getStartIndex());
               if (var4 == var5.b() - 1) {
                  var5.b(var7.getStartIndex() + var7.getLength(), var0);
               } else {
                  for(var8 = var4 + 1; var8 < var5.b() - 1; ++var8) {
                     int var9 = (Integer)var5.c(var8);
                     if (var9 < var7.getStartIndex() + var7.getLength()) {
                        var9 = (Integer)var5.c(var8 + 1);
                        if (var9 <= var7.getStartIndex() + var7.getLength()) {
                           var5.d(var8);
                           --var8;
                        } else if (var9 > var7.getStartIndex() + var7.getLength()) {
                           var5.b(var7.getStartIndex() + var7.getLength(), var7.getFont().j());
                           break;
                        }
                     } else {
                        if (var9 <= var7.getStartIndex() + var7.getLength()) {
                           break;
                        }

                        var5.b(var7.getStartIndex() + var7.getLength(), var0);
                     }
                  }
               }
            }
         }
      }

      byte[] var10 = new byte[var5.b() * 4];

      for(int var11 = 0; var11 < var5.b(); ++var11) {
         var4 = (Integer)var5.c(var11);
         var8 = (Integer)var5.b(var11);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var4), 0, var10, 4 * var11, 2);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var8), 0, var10, 4 * var11 + 2, 2);
      }

      return var10;
   }

   static void a(ArrayList var0, int var1, Font var2, boolean var3) {
      ArrayList var4 = new ArrayList();
      if (!var4.contains(0)) {
         com.aspose.cells.b.a.a.ze.a(var4, (Object)0);
      }

      if (!var4.contains(var1)) {
         com.aspose.cells.b.a.a.ze.a(var4, (Object)var1);
      }

      for(int var5 = 0; var5 < var0.size(); ++var5) {
         FontSetting var6 = (FontSetting)var0.get(var5);
         if (!var4.contains(var6.getStartIndex()) && var6.getStartIndex() < var1) {
            com.aspose.cells.b.a.a.ze.a(var4, (Object)var6.getStartIndex());
         }

         if (!var4.contains(var6.getStartIndex() + var6.getLength()) && var6.getStartIndex() + var6.getLength() < var1) {
            com.aspose.cells.b.a.a.ze.a(var4, (Object)(var6.getStartIndex() + var6.getLength()));
         }
      }

      Collections.sort(var4);
      HashMap var14 = new HashMap();
      ArrayList var15 = new ArrayList();

      for(int var7 = 0; var7 < var4.size() - 1; ++var7) {
         int var8 = (Integer)var4.get(var7);
         int var9 = (Integer)var4.get(var7 + 1);
         if (var9 <= var8 + var1) {
            FontSetting var10 = null;
            boolean var11 = false;

            for(int var12 = 0; var12 < var0.size(); ++var12) {
               var10 = (FontSetting)var0.get(var12);
               if (var8 >= var10.getStartIndex() && var9 <= var10.getStartIndex() + var10.getLength()) {
                  if (var14.containsKey(var8)) {
                     ((FontSetting)var14.get(var8)).getFont().d(var10.getFont());
                  } else {
                     FontSetting var13 = new FontSetting(var8, var9 - var8, var10.d, var10.b());
                     var13.getFont().c(var10.getFont());
                     com.aspose.cells.b.a.a.ze.a(var15, (Object)var13);
                     var14.put(var8, var13);
                  }

                  var11 = true;
               }
            }

            if (!var11) {
               FontSetting var16 = new FontSetting(var8, var9 - var8, var2.c, var3);
               var16.a(var2);
               com.aspose.cells.b.a.a.ze.a(var15, (Object)var16);
            }
         }
      }

      var0.clear();
      com.aspose.cells.b.a.a.ze.a(var0, (Collection)var15);
   }
}
